<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/6/16
 * Time: 13:59
 */

namespace app\admin\controller;

use think\Exception;

class PluginsController extends CommonController
{
    use \traits\controller\Plugins;
    public $initModel = true;
    public $is_verify = false;
    public $is_strictly = false;
    public $controller = 'Index';

    public function asyncTrigger()
    {
        try {
            $index_allow_field = implode(array_values($this->allow_field['index']), ',');
            $resultData = $this->model->lists([], $index_allow_field, '', $this->listPage);
            extract($resultData);
            if (empty($data)) {
                throw new Exception('抱歉你没有任何的插件可以加载');
            }
            foreach ($data as $key => $value) {
                list(, $name, , ,) = array_values($value);
                $uri = $this->request->module() . chr(47) . ucfirst($name);
                $this->attach(strtolower($name), $uri);
            }
            $trigger = $this->trigger();
            $this->_success($trigger, '');
        } catch (Exception $exception) {
            return $this->_error(['data' => '', 'status' => self::ERROR_CODE, 'info' => $exception->getMessage()], $exception->getCode());
        }
    }
}